package com.heima.common.tess4j;

import lombok.Data;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.awt.image.BufferedImage;

@Data
@ConfigurationProperties(prefix = "tess4j")
public class Tess4jClient {

    private String datePath;
    private String langusge;


    public String doOCR(BufferedImage image) throws TesseractException {
        //创建TEsseract对象
        Tesseract tesseract = new Tesseract();
        //设置字体语言库路径
        tesseract.setDatapath("D:\\code\\heimaconfig\\tessdata");
        //中文识别
        tesseract.setLanguage("chi_sim");
        //执行ocr
        String result = tesseract.doOCR(image);
        //replaceAll 替换格式
        result = result.replaceAll("\\r|\\n", "-").replaceAll("", "");
        //返回
        return result;
    }

}
